import { defHttp } from '@/utils/http/axios';
import { GetTaskListParams, TaskModel, CreateTaskParams, EditTaskParams, GetLogListParams } from './model/task';
import { BasicFetchResult } from '@/api/model/baseModel'


import { ErrorMessageMode } from '#/axios';

export function getTaskList(params: GetTaskListParams, mode: ErrorMessageMode = 'message') {
  return defHttp.get<BasicFetchResult<TaskModel>>(
    {
      url: '/task/schedules',
      params,
    },
    {
      errorMessageMode: mode
    }
  );
}

export function createTask(params: CreateTaskParams, mode: ErrorMessageMode = 'message') {
  return defHttp.post<TaskModel>(
    {
      url: '/task/schedules',
      params,
    },
    {
      errorMessageMode: mode,
      successMessageMode: mode,
    }
  );
}

export function editTask(id: number|string, params: EditTaskParams, mode: ErrorMessageMode = 'message') {
  return defHttp.patch<BasicFetchResult<TaskModel>>(
    {
      url: `/task/schedules/${id}`,
      params,
    },
    {
      errorMessageMode: mode,
      successMessageMode: mode,
    }
  );
}

export function deleteTask(id: number|string, mode: ErrorMessageMode = 'message') {
  return defHttp.delete(
    {
      url: `/task/schedules/${id}`,
    },
    {
      errorMessageMode: mode,
      successMessageMode: mode,
    }
  );
}

export function getLogList(params: GetLogListParams, mode: ErrorMessageMode = 'message') {
  return defHttp.get<BasicFetchResult<string>>(
    {
      url: '/task/schedules/logs',
      params,
    },
    {
      errorMessageMode: mode
    }
  );
}